import { Component, OnInit, Input } from '@angular/core';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { LocalizationService } from '@abp/ng.core';

interface TableColumnConfig {
  name: string;
  type: string;
  width: number;
  show: boolean;
  order: number;        // 列顺序
  fixed: number;        // 列固定: 0-不固定, 1-左侧固定, 2-右侧固定
}

@Component({
  selector: 'lib-table-settings-dialog',
  templateUrl: './table-settings-dialog.component.html',
  styleUrls: ['./table-settings-dialog.component.less']
})
export class TableSettingsDialogComponent implements OnInit {
  @Input() entityConfig: any;

  columns: TableColumnConfig[] = [];
  fixedOptions = [
    { value: 0, label: 'BasicArchives::UI:TableSettings.Fixed.None' },
    { value: 1, label: 'BasicArchives::UI:TableSettings.Fixed.Left' },
    { value: 2, label: 'BasicArchives::UI:TableSettings.Fixed.Right' }
  ];

  constructor(
    private modal: NzModalRef,
    private localizationService: LocalizationService
  ) {}

  ngOnInit(): void {
    this.columns = this.entityConfig.propertys.map((prop, index) => ({
      name: prop.name,
      type: prop.type,
      width: prop.width,
      show: prop.show,
      order: prop.order || index,
      fixed: prop.fixed || 0
    }));
  }

  onFixedChange(column: TableColumnConfig, value: number) {
    column.fixed = value;
  }

  saveSettings() {
    this.modal.close(this.columns);
  }

  cancel() {
    this.modal.close();
  }

  protected l(key: string): string {
    return this.localizationService.instant(key);
  }
} 